/*    */ package blockbuster.components.shape;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.components.IComponentParticleInitialize;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonArray;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ 
/*    */ public abstract class BedrockComponentShapeBase
/*    */   extends BedrockComponentBase implements IComponentParticleInitialize {
/* 14 */   public MolangExpression[] offset = new MolangExpression[] { MolangParser.ZERO, MolangParser.ZERO, MolangParser.ZERO };
/* 15 */   public ShapeDirection direction = ShapeDirection.OUTWARDS;
/*    */   
/*    */   public boolean surface = false;
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 21 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 23 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 25 */     if (element.has("offset")) {
/*    */       
/* 27 */       JsonArray array = element.getAsJsonArray("offset");
/*    */       
/* 29 */       if (array.size() >= 3) {
/*    */         
/* 31 */         this.offset[0] = parser.parseJson(array.get(0));
/* 32 */         this.offset[1] = parser.parseJson(array.get(1));
/* 33 */         this.offset[2] = parser.parseJson(array.get(2));
/*    */       } 
/*    */     } 
/*    */     
/* 37 */     if (element.has("direction")) {
/*    */       
/* 39 */       JsonElement direction = element.get("direction");
/*    */       
/* 41 */       if (direction.isJsonPrimitive()) {
/*    */         
/* 43 */         String name = direction.getAsString();
/*    */         
/* 45 */         if (name.equals("inwards")) { this.direction = ShapeDirection.INWARDS; }
/* 46 */         else { this.direction = ShapeDirection.OUTWARDS; }
/*    */       
/* 48 */       } else if (direction.isJsonArray()) {
/*    */         
/* 50 */         JsonArray array = direction.getAsJsonArray();
/*    */         
/* 52 */         if (array.size() >= 3)
/*    */         {
/* 54 */           this
/*    */ 
/*    */             
/* 57 */             .direction = new ShapeDirection.Vector(parser.parseJson(array.get(0)), parser.parseJson(array.get(1)), parser.parseJson(array.get(2)));
/*    */         }
/*    */       } 
/*    */     } 
/*    */ 
/*    */     
/* 63 */     if (element.has("surface_only"))
/*    */     {
/* 65 */       this.surface = element.get("surface_only").getAsBoolean();
/*    */     }
/*    */     
/* 68 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 74 */     JsonObject object = new JsonObject();
/* 75 */     JsonArray offset = new JsonArray();
/*    */     
/* 77 */     for (MolangExpression expression : this.offset)
/*    */     {
/* 79 */       offset.add(expression.toJson());
/*    */     }
/*    */     
/* 82 */     object.add("offset", (JsonElement)offset);
/*    */     
/* 84 */     if (this.direction != ShapeDirection.OUTWARDS)
/*    */     {
/* 86 */       object.add("direction", this.direction.toJson());
/*    */     }
/*    */     
/* 89 */     if (this.surface)
/*    */     {
/* 91 */       object.addProperty("surface_only", Boolean.valueOf(true));
/*    */     }
/*    */     
/* 94 */     return (JsonElement)object;
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\shape\BedrockComponentShapeBase.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */